import Mock from 'mockjs';
import {
  ADD_ORDER,
  DEL_ORDER,
  UPDATE_ORDER,
  // PAY_METHOD_OPT,
  // FIND_ORDER,
  // FIND_ORDER_BY_ID,
  // PAY_PLATFORM_OPT,
  // SALE_OPT,
  // ORDER_OPT,
  // PROMOTION_CHANNEL_OPT,
  // SEARCH_OPT,
  ON_SEARCH,
  UPDATE_RES,
  ADD_TEMPLATE,
  DEL_TEMPLATE,
  UPDATE_TEMPLATE,
  CHANGE_DEFAULT,
  DELIVER_STATE_OPT,
  AFTER_SALE_STATE,
  AFTER_SALE_METHOD,
  TEMPLATE_ON_SEARCH,
  TEMPLATE_RES,
} from '../../constants/order';
import { nanoid } from 'nanoid';

const Random = Mock.Random;
Mock.Random.extend({
  phone: function () {
    const phonePre = ['13', '16', '17', '18', '19']; // 自己写前缀哈
    return this.pick(phonePre) + Mock.mock(/\d{9}/); //Number()
  },
});

// 订单数据库
// const initOrderData = [];
// for (let i = 0; i < 16; i++) {
//   initOrderData.push({
//     key: i,
//     // 订单信息
//     orderId: nanoid(),
//     orderNum: Random.integer(10000, 99999),
//     orderTime: Random.datetime('yyyy-MM-dd HH:mm:ss'),
//     orderState: ORDER_OPT[Random.integer(1, 6)].label,
//     discount: '-',
//     // 商品信息
//     // goodsId: ,
//     goods: `商品${Random.word(4)}`,
//     goodsNum: Random.integer(1, 100),
//     goodsPrice:
//     paidPrice: Random.integer(1, 10000),
//     // 配送信息
//     distribute: '快递',
//     frightCharge: '???',
//     deliveryTime: '???',
//     expressCompany: '',
//     trackingNumber: Random.integer(1000, 9999),
//     // 用户信息
//     // sendId:,
//     username: Random.cname(),
//     phone: Random.phone(),
//     address: `${Random.province()}-${Random.city()}-${Random.county()}`,
//     // 用户留言
//     // 订单id 用户id
//     // userMsgId:'',
//     userMsgCont: '???',
//     userMsgTime: Random.datetime('yyyy-MM-dd HH:mm:ss'),
//     // consigneeId:
//     consignee: Random.cname(),
//     consigneePhone: Random.phone(),
//     consigneeAddress: `${Random.province()}-${Random.city()}-${Random.county()}`,
//     // 支付信息
//     // payId:nanoid(),
//     payPlatform: PAY_PLATFORM_OPT[Random.integer(1, 4)].label,
//     payMethod: PAY_METHOD_OPT[Random.integer(1, 5)].label,
//     payTime: Random.datetime('yyyy-MM-dd HH:mm:ss'),
//     payAmt: '???',
//     // 售后单id
//     afterSaleState: SALE_OPT[Random.integer(1, 2)].label,
//     // 推广渠道
//     promotionChannel: PROMOTION_CHANNEL_OPT[Random.integer(1, 5)].label,
//   });
// }
// console.log(initOrderData);
const initOrderData = [
  {
    key: 0,
    orderId: 'QaJmZlLWhcd0UrT1qxY3m',
    orderNum: 69737,
    orderTime: '2022-12-01 15:57:08',
    orderState: '待支付',
    discount: '???',
    goods: '商品kbvx',
    goodsNum: 89,
    paidPrice: 8165,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 8077,
    username: '戴磊',
    phone: '13925929634',
    address: '宁夏回族自治区-上海市-泾源县',
    userMsgCont: '???',
    userMsgTime: '2022-10-12 17:59:37',
    consignee: '龚敏',
    consigneePhone: '16289545476',
    consigneeAddress: '云南省-百色市-额济纳旗',
    payPlatform: 'M站',
    payMethod: '花呗分期',
    payTime: '2009-05-11 14:04:55',
    payAmt: '???',
    afterSaleState: '售后中',
    promotionChannel: '小红书订单',
  },
  {
    key: 1,
    orderId: 'MWrrzHYjf1rVSVt_ypZff',
    orderNum: 36836,
    orderTime: '2022-04-29 14:07:11',
    orderState: '待发货',
    discount: '???',
    goods: '商品ksyl',
    goodsNum: 22,
    paidPrice: 2720,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 8468,
    username: '任平',
    phone: '18897389848',
    address: '山西省-张家口市-南沙群岛',
    userMsgCont: '???',
    userMsgTime: '2022-03-07 21:20:38',
    consignee: '孙霞',
    consigneePhone: '17483282163',
    consigneeAddress: '宁夏回族自治区-松原市-隆昌县',
    payPlatform: 'M站',
    payMethod: '花呗支付',
    payTime: '2004-04-05 09:04:27',
    payAmt: '???',
    afterSaleState: '售后结束',
    promotionChannel: '支付宝商家小程序',
  },
  {
    key: 2,
    orderId: 'PJMxvJsO477stv7iutRbw',
    orderNum: 53291,
    orderTime: '2000-10-31 12:53:12',
    orderState: '已发货',
    discount: '???',
    goods: '商品eixs',
    goodsNum: 26,
    paidPrice: 4715,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '申通快递',
    trackingNumber: 1855,
    username: '郑霞',
    phone: '19881276799',
    address: '新疆维吾尔自治区-佛山市-弓长岭区',
    userMsgCont: '???',
    userMsgTime: '1996-02-08 03:38:24',
    consignee: '锺勇',
    consigneePhone: '18394763845',
    consigneeAddress: '新疆维吾尔自治区-南昌市-朝阳区',
    payPlatform: 'APP',
    payMethod: '银联支付',
    payTime: '1980-05-18 16:34:46',
    payAmt: '???',
    afterSaleState: '售后结束',
    promotionChannel: '腾讯惠聚',
  },
  {
    key: 3,
    orderId: 'f3t_dnJF2OMGxGo5U3-_2',
    orderNum: 20251,
    orderTime: '2022-02-10 06:34:39',
    orderState: '已完成',
    discount: '???',
    goods: '商品sjua',
    goodsNum: 67,
    paidPrice: 7931,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 3090,
    username: '谢军',
    phone: '18126526640',
    address: '台湾-和田地区-印台区',
    userMsgCont: '???',
    userMsgTime: '1985-07-26 04:37:11',
    consignee: '苏艳',
    consigneePhone: '19116215254',
    consigneeAddress: '江苏省-天津市-类乌齐县',
    payPlatform: 'M站',
    payMethod: '花呗分期',
    payTime: '1993-08-23 07:13:58',
    payAmt: '???',
    afterSaleState: '售后结束',
    promotionChannel: '小红书订单',
  },
  {
    key: 4,
    orderId: 'xbTLMWaGPmqGIMVUN4Bhr',
    orderNum: 48681,
    orderTime: '2022-12-30 02:24:54',
    orderState: '已关闭',
    discount: '???',
    goods: '商品wgmo',
    goodsNum: 77,
    paidPrice: 5599,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 4631,
    username: '赖敏',
    phone: '17271364071',
    address: '山西省-海北藏族自治州-沙田区',
    userMsgCont: '???',
    userMsgTime: '1985-10-18 11:54:37',
    consignee: '段艳',
    consigneePhone: '13567014474',
    consigneeAddress: '河南省-鞍山市-鄂托克前旗',
    payPlatform: 'APP',
    payMethod: '微信支付',
    payTime: '2022-03-07 15:06:46',
    payAmt: '???',
    afterSaleState: '售后结束',
    promotionChannel: '小红书订单',
  },
  {
    key: 5,
    orderId: 'FvbcIR4h3ARfDILwT0wuM',
    orderNum: 26591,
    orderTime: '2022-12-23 07:32:44',
    orderState: '售后中',
    discount: '???',
    goods: '商品mbvm',
    goodsNum: 51,
    paidPrice: 547,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 3690,
    username: '袁勇',
    phone: '17161119911',
    address: '陕西省-昌都地区--',
    userMsgCont: '???',
    userMsgTime: '1981-07-25 19:21:58',
    consignee: '吕明',
    consigneePhone: '17378040598',
    consigneeAddress: '重庆-辽阳市-其它区',
    payPlatform: '小程序',
    payMethod: '银联支付',
    payTime: '2001-01-10 11:11:45',
    payAmt: '???',
    afterSaleState: '售后结束',
    promotionChannel: '支付宝商家小程序',
  },
  {
    key: 6,
    orderId: 'ttwwFFZTK0KJZqAw9SPKt',
    orderNum: 80301,
    orderTime: '2021-06-19 17:52:09',
    orderState: '待支付',
    discount: '???',
    goods: '商品mmnt',
    goodsNum: 38,
    paidPrice: 8383,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 5982,
    username: '徐洋',
    phone: '18259154525',
    address: '吉林省-嘉兴市-靖宇县',
    userMsgCont: '???',
    userMsgTime: '2017-04-09 15:42:46',
    consignee: '石敏',
    consigneePhone: '19625807654',
    consigneeAddress: '新疆维吾尔自治区-临沧市-丹徒区',
    payPlatform: 'APP',
    payMethod: '微信支付',
    payTime: '2007-12-29 22:53:34',
    payAmt: '???',
    afterSaleState: '售后结束',
    promotionChannel: '微信小店',
  },
  {
    key: 7,
    orderId: 'm5jlXuj9jYFeoyAn7xRTC',
    orderNum: 75165,
    orderTime: '1989-02-17 20:41:01',
    orderState: '待发货',
    discount: '???',
    goods: '商品urkf',
    goodsNum: 34,
    paidPrice: 8020,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 5516,
    username: '易静',
    phone: '18564238244',
    address: '甘肃省-宜昌市-中沙群岛的岛礁及其海域',
    userMsgCont: '???',
    userMsgTime: '1985-01-12 23:25:27',
    consignee: '冯芳',
    consigneePhone: '19177466181',
    consigneeAddress: '海南省-博尔塔拉蒙古自治州-碾子山区',
    payPlatform: 'APP',
    payMethod: '银联支付',
    payTime: '1998-11-17 02:34:19',
    payAmt: '???',
    afterSaleState: '售后中',
    promotionChannel: '腾讯惠聚',
  },
  {
    key: 8,
    orderId: '9GMhIeh4gyHSg5XE30L9H',
    orderNum: 33706,
    orderTime: '1988-10-01 01:05:59',
    orderState: '售后中',
    discount: '???',
    goods: '商品zoym',
    goodsNum: 60,
    paidPrice: 7155,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 5562,
    username: '黄静',
    phone: '16519764898',
    address: '湖北省-佛山市-大通回族土族自治县',
    userMsgCont: '???',
    userMsgTime: '1987-11-28 04:15:21',
    consignee: '刘霞',
    consigneePhone: '17277003404',
    consigneeAddress: '四川省-镇江市-岷县',
    payPlatform: 'PC官网',
    payMethod: '支付宝支付',
    payTime: '2010-06-28 10:39:15',
    payAmt: '???',
    afterSaleState: '售后中',
    promotionChannel: '抖音直播',
  },
  {
    key: 9,
    orderId: 'pHh_TGhc4ePFZ4c_QW_Ny',
    orderNum: 79204,
    orderTime: '1973-07-27 19:06:21',
    orderState: '待发货',
    discount: '???',
    goods: '商品bqfd',
    goodsNum: 86,
    paidPrice: 5846,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 1346,
    username: '廖勇',
    phone: '16475768445',
    address: '甘肃省-重庆市-郊区',
    userMsgCont: '???',
    userMsgTime: '1978-11-24 06:14:12',
    consignee: '潘伟',
    consigneePhone: '19146975115',
    consigneeAddress: '山东省-南平市-绍兴县',
    payPlatform: 'APP',
    payMethod: '微信支付',
    payTime: '2013-05-02 21:07:40',
    payAmt: '???',
    afterSaleState: '售后结束',
    promotionChannel: '小红书订单',
  },
  {
    key: 10,
    orderId: 'xdHrPvX-vxGK3l692gTIx',
    orderNum: 99587,
    orderTime: '1991-10-07 14:19:43',
    orderState: '待发货',
    discount: '???',
    goods: '商品xfhj',
    goodsNum: 61,
    paidPrice: 2731,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 4020,
    username: '尹霞',
    phone: '19912882444',
    address: '海南省-兴安盟-化隆回族自治县',
    userMsgCont: '???',
    userMsgTime: '1982-02-17 17:52:27',
    consignee: '郝军',
    consigneePhone: '19121818303',
    consigneeAddress: '江苏省-上海市-荷塘区',
    payPlatform: 'PC官网',
    payMethod: '花呗分期',
    payTime: '1983-11-22 06:10:17',
    payAmt: '???',
    afterSaleState: '售后结束',
    promotionChannel: '微信小店',
  },
  {
    key: 11,
    orderId: 'NK4xkIQVy5TFHcr5a7KYe',
    orderNum: 78092,
    orderTime: '2008-07-30 07:17:24',
    orderState: '已关闭',
    discount: '???',
    goods: '商品foga',
    goodsNum: 75,
    paidPrice: 9513,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 6281,
    username: '万涛',
    phone: '13001471862',
    address: '上海-淮北市--',
    userMsgCont: '???',
    userMsgTime: '1996-01-30 21:30:37',
    consignee: '潘军',
    consigneePhone: '17875314511',
    consigneeAddress: '广东省-郴州市-浉河区',
    payPlatform: 'PC官网',
    payMethod: '花呗支付',
    payTime: '1988-12-30 09:15:52',
    payAmt: '???',
    afterSaleState: '售后结束',
    promotionChannel: '小红书订单',
  },
  {
    key: 12,
    orderId: 'y0euXZ7TBQ2r6f4ue2Djt',
    orderNum: 50380,
    orderTime: '2002-11-07 08:20:32',
    orderState: '售后中',
    discount: '???',
    goods: '商品vvwl',
    goodsNum: 80,
    paidPrice: 7893,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 6957,
    username: '韩强',
    phone: '19061357102',
    address: '吉林省-淮北市-芗城区',
    userMsgCont: '???',
    userMsgTime: '1997-05-04 02:55:17',
    consignee: '范明',
    consigneePhone: '16675463771',
    consigneeAddress: '甘肃省-衡阳市-嵊州市',
    payPlatform: 'M站',
    payMethod: '花呗分期',
    payTime: '1987-01-24 12:39:00',
    payAmt: '???',
    afterSaleState: '售后结束',
    promotionChannel: '抖音直播',
  },
  {
    key: 13,
    orderId: 'ksJlh2TNQ10ljmU7vCanX',
    orderNum: 10287,
    orderTime: '1981-08-08 07:19:04',
    orderState: '已完成',
    discount: '???',
    goods: '商品ccpy',
    goodsNum: 38,
    paidPrice: 8150,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 3970,
    username: '田勇',
    phone: '16515529765',
    address: '黑龙江省-塔城地区-七堵区',
    userMsgCont: '???',
    userMsgTime: '2014-06-25 08:08:25',
    consignee: '孔超',
    consigneePhone: '17588138910',
    consigneeAddress: '山东省-固原市-岫岩满族自治县',
    payPlatform: 'M站',
    payMethod: '花呗分期',
    payTime: '1984-07-21 11:57:03',
    payAmt: '???',
    afterSaleState: '售后结束',
    promotionChannel: '微信小店',
  },
  {
    key: 14,
    orderId: 'CEw0caohO8FK6rx5RXKR7',
    orderNum: 72956,
    orderTime: '1975-12-05 20:21:15',
    orderState: '待发货',
    discount: '???',
    goods: '商品jawu',
    goodsNum: 92,
    paidPrice: 4944,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 9732,
    username: '刘军',
    phone: '18878774872',
    address: '西藏自治区-固原市-左贡县',
    userMsgCont: '???',
    userMsgTime: '1991-06-19 01:30:38',
    consignee: '邵洋',
    consigneePhone: '13229970050',
    consigneeAddress: '山东省-屏东县-广安区',
    payPlatform: 'PC官网',
    payMethod: '花呗分期',
    payTime: '1983-02-12 19:56:36',
    payAmt: '???',
    afterSaleState: '售后结束',
    promotionChannel: '腾讯惠聚',
  },
  {
    key: 15,
    orderId: 'AVl3_zYtZfz8VS8UQIV38',
    orderNum: 33179,
    orderTime: '1997-07-29 02:08:45',
    orderState: '已关闭',
    discount: '???',
    goods: '商品ldwu',
    goodsNum: 13,
    paidPrice: 517,
    distribute: '快递',
    frightCharge: '???',
    deliveryTime: '???',
    expressCompany: '',
    trackingNumber: 5080,
    username: '周洋',
    phone: '17964732281',
    address: '山东省-澳门半岛-沂源县',
    userMsgCont: '???',
    userMsgTime: '2000-06-07 03:39:49',
    consignee: '白敏',
    consigneePhone: '18436348679',
    consigneeAddress: '宁夏回族自治区-衡阳市-蒙城县',
    payPlatform: 'APP',
    payMethod: '花呗支付',
    payTime: '2018-07-08 21:36:07',
    payAmt: '???',
    afterSaleState: '售后中',
    promotionChannel: '腾讯惠聚',
  },
];

// 订单reducer
export function orderReducer(preState = initOrderData, action) {
  const { type, payload } = action;
  switch (type) {
    case ADD_ORDER:
      return [...preState, payload];
    case DEL_ORDER:
      return preState.filter(el => el.id !== payload);
    case UPDATE_ORDER: {
      // console.log(payload);
      const { id, newState } = payload;
      const newArr = preState.map(el => {
        if (el.orderId === id) return { ...el, ...newState };
        return el;
      });
      return newArr;
    }
    // 不能在这里筛选，会改变数据源
    default:
      return preState;
  }
}

// 订单 搜索
export const searchReducer = (preState = false, action) => {
  const { type, payload } = action;
  switch (type) {
    case ON_SEARCH: {
      // console.log(payload);
      return payload;
    }
    default:
      return preState;
  }
};

export const searchResReducer = (preState = [], action) => {
  const { type, payload } = action;
  switch (type) {
    case UPDATE_RES:
      return payload;
    default:
      return preState;
  }
};

// 配送模板原始数据
const initTemplateData = [
  {
    id: nanoid(),
    name: '生鲜类配送模板',
    isDefault: false,
    updateTime: '2022-05-24 09:57:12',
    distributeArea: '上海、浙江、江苏',
    priceType: '按件数',
    firstPiece: 1,
    unitFee: 8,
    addPiece: 1,
    addFee: 5,
    relatedGoodsNum: 299,
  },
  {
    id: nanoid(),
    name: '电器类配送模板',
    isDefault: true,
    updateTime: '2022-06-24 09:57:12',
    distributeArea: '辽宁、吉林、黑龙江',
    priceType: '按重量',
    firstWeight: 1,
    unitFeeW: 10,
    addWeight: 1,
    addFeeW: 5,
    relatedGoodsNum: 199,
  },
  {
    id: nanoid(),
    name: '微小件配送模板',
    isDefault: false,
    updateTime: '2022-07-24 09:57:12',
    distributeArea: '青海、甘肃',
    priceType: '按重量',
    firstWeight: 1,
    unitFeeW: 10,
    addWeight: 1,
    addFeeW: 5,
    relatedGoodsNum: 99,
  },
  {
    id: nanoid(),
    name: '大体积配送模板',
    isDefault: false,
    updateTime: '2022-12-24 09:57:12',
    distributeArea: '北京、天津、河北、山东',
    priceType: '按件数',
    firstPiece: 1,
    unitFee: 10,
    addPiece: 1,
    addFee: 5,
    relatedGoodsNum: 99,
  },
];
// 配送 reducer
export function templateReducer(preState = initTemplateData, action) {
  const { type, payload } = action;
  switch (type) {
    case ADD_TEMPLATE:
      return [{ ...payload }, ...preState].sort(
        (a, b) => b.isDefault - a.isDefault
      );
    case DEL_TEMPLATE:
      return preState.filter(el => el.id !== payload);
    case UPDATE_TEMPLATE: {
      const { id, newState } = payload;
      const newArr = preState.map(el => {
        if (el.id === id) return { ...el, ...newState };
        return el;
      });
      return newArr;
    }
    case CHANGE_DEFAULT:
      return preState
        .map(el => {
          if (el.id === payload) return { ...el, isDefault: true };
          else return { ...el, isDefault: false };
        })
        .sort((a, b) => b.isDefault - a.isDefault);
    default:
      return preState.sort((a, b) => b.isDefault - a.isDefault);
  }
}

// 配送 搜索
export const templateSearchReducer = (preState = false, action) => {
  const { type, payload } = action;
  switch (type) {
    case TEMPLATE_ON_SEARCH: {
      // console.log(payload);
      return payload;
    }
    default:
      return preState;
  }
};

export const templateRes = (preState = [], action) => {
  const { type, payload } = action;
  switch (type) {
    case TEMPLATE_RES:
      // console.log('搜索结果', payload);
      return payload;
    default:
      return preState;
  }
};

// 售后 reducer
const initAfterSaleData = [
  {
    key: 0,
    id: 'L0iRWuhEDffrrBCy-ibKy',
    soldNum: 24540,
    orderNum: 82441,
    goods: '商品dybh',
    deliverState: '未发货',
    soldState: '退货退款',
    payAmt: 8528,
    refundAmt: '???',
    applicationDate: '1990-11-25 15:34:17',
    timeOut: '???',
    state: '售后申请待商家处理',
  },
  {
    key: 1,
    id: '16J5qcoeygHEsC2aDc-KM',
    soldNum: 42207,
    orderNum: 55510,
    goods: '商品xbvb',
    deliverState: '已发货',
    soldState: '退货退款',
    payAmt: 4067,
    refundAmt: '???',
    applicationDate: '2005-06-25 09:27:09',
    timeOut: '???',
    state: '商家不同意，待买家处理',
  },
  {
    key: 2,
    id: 'vkXn3d6CnzDeIPRYB0F7q',
    soldNum: 33854,
    orderNum: 38154,
    goods: '商品dztp',
    deliverState: '未发货',
    soldState: '退货退款',
    payAmt: 6991,
    refundAmt: '???',
    applicationDate: '1988-07-26 11:23:54',
    timeOut: '???',
    state: '商家已同意，待买家处理',
  },
  {
    key: 3,
    id: 'ICaf3JYD1dk9yWeXk9en9',
    soldNum: 24272,
    orderNum: 68635,
    goods: '商品suqn',
    deliverState: '未发货',
    soldState: '退货退款',
    payAmt: 3302,
    refundAmt: '???',
    applicationDate: '2014-02-07 22:55:08',
    timeOut: '???',
    state: '买家已退货，待商家收货',
  },
  {
    key: 4,
    id: 'Aw3StiIFaSX7bCWfYfCOf',
    soldNum: 63368,
    orderNum: 10929,
    goods: '商品yosm',
    deliverState: '已发货',
    soldState: '换货',
    payAmt: 4717,
    refundAmt: '???',
    applicationDate: '2001-05-08 23:07:17',
    timeOut: '???',
    state: '商家拒绝收货，待买家处理',
  },
  {
    key: 5,
    id: 'vLSFtVevAV4dWhT-tERhR',
    soldNum: 75485,
    orderNum: 88834,
    goods: '商品haip',
    deliverState: '已发货',
    soldState: '换货',
    payAmt: 4432,
    refundAmt: '???',
    applicationDate: '1980-06-19 22:59:26',
    timeOut: '???',
    state: '商家已收货，待买家收货',
  },
  {
    key: 6,
    id: 'SzoUUGF0oJQZIo5MO4bCt',
    soldNum: 69983,
    orderNum: 54919,
    goods: '商品jsfw',
    deliverState: '未发货',
    soldState: '退货退款',
    payAmt: 6010,
    refundAmt: '???',
    applicationDate: '2019-07-02 10:33:17',
    timeOut: '???',
    state: '售后成功',
  },
  {
    key: 7,
    id: 'uKNmJR5wIF5ktEatxhj7z',
    soldNum: 25426,
    orderNum: 26184,
    goods: '商品uncw',
    deliverState: '已发货',
    soldState: '换货',
    payAmt: 154,
    refundAmt: '???',
    applicationDate: '1986-01-28 08:06:39',
    timeOut: '???',
    state: '售后关闭',
  },
];
for (let i = 0; i < 5; i++) {
  initAfterSaleData.push({
    key: i + 100,
    // 售后信息
    id: nanoid(),
    soldNum: Random.integer(10000, 99999),
    orderNum: Random.integer(10000, 99999),
    goods: `商品${Random.word(4)}`,
    deliverState: DELIVER_STATE_OPT[Random.integer(1, 2)].label,
    soldState: AFTER_SALE_METHOD[Random.integer(1, 3)].label,
    payAmt: Random.integer(1, 10000),
    refundAmt: '???',
    applicationDate: Random.datetime('yyyy-MM-dd HH:mm:ss'),
    timeOut: '???',
    state: AFTER_SALE_STATE[Random.integer(0, 6)].label,
  });
}
// console.log(initAfterSaleData);

export function soldReducer(preState = initAfterSaleData, action) {
  const { type } = action;
  switch (type) {
    // case ADD_ORDER:
    //   return [...preState, payload];
    // case DEL_ORDER:
    //   return preState.filter(el => el.id !== payload);
    // case UPDATE_ORDER: {
    //   console.log(payload);
    //   const { id, newState } = payload;
    //   const newArr = preState.map(el => {
    //     if (el.orderId === id) return { ...el, ...newState };
    //     return el;
    //   });
    //   return newArr;
    // }
    default:
      return preState;
  }
}

// 售后 搜索
export const soldSearchReducer = (preState = false, action) => {
  const { type, payload } = action;
  switch (type) {
    case ON_SEARCH: {
      return payload;
    }
    default:
      return preState;
  }
};

export const soldSearchResReducer = (preState = [], action) => {
  const { type, payload } = action;
  switch (type) {
    case UPDATE_RES:
      return payload;
    default:
      return preState;
  }
};
